package com.xunker.user.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xunker.appointment.model.patient.Patient;

import com.xunker.client.DictFeignClient;
import com.xunker.user.mapper.PatientMapper;
import com.xunker.user.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PatientServiceImpl  extends ServiceImpl<PatientMapper, Patient> implements PatientService {
    @Autowired
    private DictFeignClient dictFeignClient;
    @Override
    public List<Patient> findAllUserId(Long userId) {
        Map<String, Object> param = new HashMap<>();
        //同一个病人可能去不同的部门挂号，故有多个值
        QueryWrapper<Patient> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<Patient> patients = baseMapper.selectList(wrapper);
        //编号转换字符串
        patients.stream().forEach(s->{
            param.put("certificatesTypeString",dictFeignClient.getNameByCN("CertificatesType",s.getCertificatesType()));
            param.put("contactsCertificatesTypeString",dictFeignClient.getNameByCN("CertificatesType",s.getContactsCertificatesType()));
            param.put("provinceCodeString",dictFeignClient.getNameByCN("PROVINCE",s.getProvinceCode()));
            param.put("cityCodeString",dictFeignClient.getNameByCN("CITY",s.getCityCode()));
            param.put("districtCodeString",dictFeignClient.getNameByCN("DISTRICT",s.getDistrictCode()));
            s.setParam(param);
        });
        return patients;
    }

    @Override
    public Patient getPatientId(Long id) {
        Map<String, Object> param = new HashMap<>();
        Patient patient = baseMapper.selectById(id);
        param.put("certificatesTypeString",dictFeignClient.getNameByCN("CertificatesType",patient.getCertificatesType()));
        param.put("contactsCertificatesTypeString",dictFeignClient.getNameByCN("CertificatesType",patient.getContactsCertificatesType()));
        param.put("provinceCodeString",dictFeignClient.getNameByCN("PROVINCE",patient.getProvinceCode()));
        param.put("cityCodeString",dictFeignClient.getNameByCN("CITY",patient.getCityCode()));
        param.put("districtCodeString",dictFeignClient.getNameByCN("DISTRICT",patient.getDistrictCode()));
        patient.setParam(param);
        return patient;
    }
}
